
*******************************************************************
*******************************************************************
************************* Table 2 : *******************************
*******************************************************************
*******************************************************************

set more off
use  "${data}Panel_quarterly.dta", replace

** Sample:

keep if analysis_sample==1
duplicates drop spell_identifier, force

** Infividual characteristics:

merge 1:1 spell_identifier using "${data}Cross_section.dta"
keep if _merge ==3
drop _merge

** Label:

label var ind_female  "Female"
label var ind_single  "Single"
label var ind_nb_children  "Children number"
label var ind_part_time  "Looks for part time job"
label var ind_middleschool  "Middle school level"
label var ind_highschool  "General_highschool_level"
label var ind_technical  "Vocational highschool level"
label var ind_superior  "Higher education level"
label var ind_blue_low_skill  "Blue collar, unskilled"
label var ind_white_low_skill  "White collar, unskilled"
label var ind_white_skill  "White collar"
label var ind_blue_skill  "Blue collar"
label var ind_age  "Age"
label var ind_exp  "Prior occupational experience"
label var ind_cum_duration_year  "Cumulated past unemployment"
label var ind_motive_endc  "Contract ended at term"
label var ind_motive_endool  "Was out-of-labor-force"
label var ind_motive_ind_laidoff  "Was laid-off_for ind reasons"
label var ind_motive_mass_laidoff  "Was laid-off for econ reasons"
label var ind_motive_quit  "Quit"
label var ind_motive_rupture_conv  "Contract ended with agreement"
label var ind_motive_firstjob  "New entrant on labor market"
label var Nbprevious "Number prior U spells"
label var ind_int_mgmt "Management"
label var ind_exp "Professional experience"
label var ind_full_time "Looks for full time job"
label var UI "Eligible for UI"
label var ODD_ref_wage_hourly "Previous hourly wage"
label var ODD_ref_wage_monthly "Previous monthly wage"
label var pjc_amount_benefit_monthly "Monthly UI benefits"

*******************************************************************
** Summary stats     **********************************************
*******************************************************************

** Count number of spells

 set more off
 matrix Xmid1=.,.,.,.
 foreach var in   ind_female ind_age ind_single ind_full_time   ind_exp ind_cum_duration_year  UI {
 su `var', d
sca A1= round(r(mean),0.01)
sca A2= round(r(sd),0.01)
 su `var' if balanced_sample==1, d
sca A3= round(r(mean),0.01)
sca A4= round(r(sd),0.01)
mat Xmid= A1,A2,A3,A4
local varlabel : var label `var'
mat rownames Xmid="`varlabel'"
mat Xmid1=Xmid1\Xmid
}

** Education level

 set more off
 matrix Xmid=.,.,.,.
 mat rownames Xmid="Education_level"
 mat Xmid1=Xmid1\Xmid
 foreach var in ind_middleschool ind_technical ind_highschool   ind_superior {
 su `var', d
sca A1= round(r(mean),0.01)
sca A2= round(r(sd),0.01)
 su `var' if balanced_sample==1, d
sca A3= round(r(mean),0.01)
sca A4= round(r(sd),0.01)
mat Xmid= A1,A2,A3,A4
local varlabel : var label `var'
mat rownames Xmid="`varlabel'"
mat Xmid1=Xmid1\Xmid
}

** Skill level

 set more off
 matrix Xmid=.,.,.,.
 mat rownames Xmid="Skill_level"
 mat Xmid1=Xmid1\Xmid
 foreach var in ind_blue_low_skill ind_blue_skill ind_white_low_skill ind_white_skill    ind_int_mgmt {
 su `var', d
sca A1= round(round(r(mean),0.01),0.01)
sca A2= round(r(sd),0.01)
 su `var' if balanced_sample==1, d
sca A3= round(r(mean),0.01)
sca A4= round(r(sd),0.01)
mat Xmid= A1,A2,A3,A4
local varlabel : var label `var'
mat rownames Xmid="`varlabel'"
mat Xmid1=Xmid1\Xmid
}



** Motive for unemployment


 set more off
 matrix Xmid=.,.,.,.
 mat rownames Xmid="Motive_for_unemployment"
 mat Xmid1=Xmid1\Xmid
 foreach var in ind_motive_endc ind_motive_rupture_conv ind_motive_ind_laidoff ind_motive_mass_laidoff ind_motive_quit  ind_motive_firstjob  {
 su `var', d
sca A1= round(r(mean),0.01)
sca A2= round(r(sd),0.01)
 su `var' if balanced_sample==1, d
sca A3= round(r(mean),0.01)
sca A4= round(r(sd),0.01)
mat Xmid= A1,A2,A3,A4
local varlabel : var label `var'
mat rownames Xmid="`varlabel'"
mat Xmid1=Xmid1\Xmid
}


** UI information

 set more off
 matrix Xmid=.,.,.,.
 mat rownames Xmid="UI_information"
 mat Xmid1=Xmid1\Xmid
 foreach var in ODD_ref_wage_hourly ODD_ref_wage_monthly pjc_amount_benefit_monthly {
 su `var', d
sca A1= round(round(r(mean),0.01),0.01)
sca A2= round(r(sd),0.01)
 su `var' if balanced_sample==1, d
sca A3= round(r(mean),0.01)
sca A4= round(r(sd),0.01)
mat Xmid= A1,A2,A3,A4
local varlabel : var label `var'
mat rownames Xmid="`varlabel'"
mat Xmid1=Xmid1\Xmid
}


** Count number of spells

count if !missing(balanced_sample)
sca A1= r(N)
count if  balanced_sample==1
sca A2= r(N)
mat Xmid= A1,.,A2,.
mat rownames Xmid="Number of spells"
mat Xmid1=Xmid1\Xmid

** Count number of unique indiviuals

preserve
duplicates drop ind_identifier, force
count if !missing(balanced_sample)
sca A1= r(N)
count if  balanced_sample==1
sca A2= r(N)
mat Xmid= A1,.,A2,.
mat rownames Xmid="Number of individuals"
mat Xmid1=Xmid1\Xmid
restore

mat list Xmid1

putexcel A1=matrix(Xmid1, names)  using Table2, replace
putexcel A1=(" ") B1=("Full sample") C1=("Full sample") D1=("Balanced sample") E1=("Balanced sample") using Table2, modify
putexcel A2=(" ") B2=("Mean") C2=("SD") D2=("Mean") E2=("SD") using Table2, modify


